package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.Brand;
import com.nbsaas.boot.product.api.domain.simple.BrandSimple;

import com.nbsaas.boot.rest.api.Converter;
import java.util.HashMap;
import java.util.Map;

/**
* 品牌-列表对象转换器
*/

public class BrandSimpleConvert implements Converter<BrandSimple, Brand> {




@Override
public BrandSimple convert(Brand source) {
    BrandSimple result = new BrandSimple();

                result.setCountry(source.getCountry());
                result.setNote(source.getNote());

               try {
                   if(source.getCreator()!=null){
                       result.setCreator(source.getCreator().getId());
                   }
                } catch (Exception ignored) { }

                result.setCode(source.getCode());

                try {
                    if(source.getCreator()!=null){
                        result.setCreatorName(source.getCreator().getName());
                    }
                } catch (Exception ignored) { }

                result.setAddDate(source.getAddDate());
                result.setUrl(source.getUrl());
                result.setName(source.getName());
                result.setLogo(source.getLogo());
                result.setSortNum(source.getSortNum());
                if(source.getState()!=null){
                   Map<Integer,String> StateMap=new HashMap<>();
                       StateMap.put(-1,"禁用");
                       StateMap.put(1,"启用");
                   String label=  StateMap.get(source.getState());
                   result.setStateName(label);
                }
                result.setState(source.getState());
                result.setId(source.getId());
                result.setLastDate(source.getLastDate());


    return result;
}

}